import Vue from "vue"
import Vuex from "vuex"
import createLogger from 'vuex/dist/logger';

Vue.use(Vuex)
const debug = process.env.NODE_ENV !== 'production'; 
export default new Vuex.Store({
    state:{
        token:sessionStorage.getItem("token"),
        name:sessionStorage.getItem("name"),
        article:JSON.parse(sessionStorage.getItem("article")),
        atcSearch:JSON.parse(sessionStorage.getItem("atcSearch")),
        isShow:false
    },
    getters:{
        userName(state){
            return state.name
        }
    },
    mutations:{
        changeisShow(state,isShow){
            state.isShow=isShow
        },
        //保存token
        savetoken(state,token){
            sessionStorage.setItem("token",token)
            state.token=token
        },
        //保存用户名
        savename(state,name){
            sessionStorage.setItem("name",name)
            state.name=name
        },
        //提交文章分页内容
        savearticle(state,article){
            sessionStorage.setItem("article",JSON.stringify(article))
            state.article=article
        },
        //根据标签搜索文章
        getInner(state,atcSearch){
            sessionStorage.setItem("atcSearch",JSON.stringify(atcSearch))
            state.atcSearch=atcSearch
        }
    },
    actions:{

    },
    strict: debug, //开启 debug选项
    plugins: debug ? [createLogger()] : []
})